import http from '/@lib/utils/http/request'
import { UserForm, UserQuery, UserVO } from './types'

export const ApiSysUser: any = {}

/**
 * 查询用户管理列表
 */
ApiSysUser.page = (queryParam?: UserQuery): Promise<PageResult<UserVO[]>> => {
  return http.get('/sysUser/page', queryParam)
}

ApiSysUser.getInfo = (userId: string | number): Promise<UserVO> => {
  return http.get('/sysUser/getInfo/' + userId)
}

/**
 * 新增客户端管理
 * @param data
 */
ApiSysUser.save = (data: UserForm) => {
  return http.post('/sysUser/save', data)
}

/**
 * 修改客户端管理
 * @param data
 */
ApiSysUser.update = (data: UserForm) => {
  return http.post('/sysUser/update', data)
}

/**
 * 删除客户端管理
 * @param id
 */
ApiSysUser.remove = (id: string | number | Array<string | number>) => {
  return http.post('/sysUser/remove/' + id)
}

/**
 * 状态修改
 * @param id ID
 * @param status 状态
 */
ApiSysUser.changeStatus = (id: number | string, status: string) => {
  const data = {
    userId: id,
    status
  }
  return http.postParams('/sysUser/changeStatus', data)
}

/**
 * 保存授权角色
 * @param params 用户ID
 */
ApiSysUser.authRole = (params: { userId: string; roleIds: string }) => {
  return http.postParams('/sysUser/authRole', params)
}

/**
 * 根据用户ID获取授权角色 和 查询角色集合
 * @param userId
 */
ApiSysUser.getAuthRole = (userId: string | number) => {
  return http.get('/sysUser/authRole/' + userId)
}

/**
 * 查询当前部门的所有用户信息
 * @param deptId
 */
ApiSysUser.listUserByDeptId = (deptId: string | number): Promise<UserVO[]> => {
  return http.get('/sysUser/list/dept/' + deptId)
}
